package com.iwuke.dance.wallet.balance;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.DefaultView;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.SharedPreferencesUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;
import com.iwuke.dance.wallet.balance.adapter.ItemBalanceDetailsAdapter;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.recyclerview.widget.RecyclerView;
import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/9/25
 * 余额
 */
public class BalanceActivity  extends BaseActivity implements View.OnClickListener {


    private ImageView img_left;
    private RecyclerView recycler_view;
    private ImageView img_right;
    private TextView tv_all;
    private TextView tv_balance;
    private TextView tv_withdraw;
    private DefaultView default_view;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(BalanceActivity.this,networkEvent,null);
    }

    @Override
    protected int getView() {
        return R.layout.activity_balance;
    }

    @Override
    protected void init(View mView) {

        //返回
        img_left = findViewById(R.id.img_left);

        //余额
        tv_balance = findViewById(R.id.tv_balance);
        tv_balance.setText("0.0元");
        //提现按钮
        tv_withdraw = findViewById(R.id.tv_withdraw);

        //余额变动明细
        img_right = findViewById(R.id.img_right);
        //余额变动明细
        tv_all = findViewById(R.id.tv_all);

        //列表
        recycler_view = findViewById(R.id.recycler_view);
        //默认页面
        default_view = findViewById(R.id.default_view);


        //返回
        img_left.setOnClickListener(this);
        //提现按钮
        tv_withdraw.setOnClickListener(this);
        //余额变动明细
        img_right.setOnClickListener(this);
        //余额变动明细
        tv_all.setOnClickListener(this);
    }

    @Override
    protected void initData() {

        transactionRecordHomepage();

    }

    private void transactionRecordHomepage(){
        Map<String, String> map = new HashMap<>();
        map.put("walletId", SharedPreferencesUtil.getInstance().getWalletId());
        PathUrl.transactionRecordHomepage(map, new PathUrl.DataCallBackList<StarlightTransactionRecordHomepageBean>() {
            @Override
            public void onSucessList(List<StarlightTransactionRecordHomepageBean> lists) {
                //默认页面
                default_view.setVisibility(View.GONE);
                if (lists!=null&&lists.size()>0){
                    setLinearLayoutManager(BalanceActivity.this,recycler_view);
                    ItemBalanceDetailsAdapter adapter = new ItemBalanceDetailsAdapter(BalanceActivity.this, R.layout.adapter_item_balance_details, lists);
                    recycler_view.setAdapter(adapter);
                }else {
                    default_view.setVisibility(View.VISIBLE);
                    default_view.setTextView(getString(R.string.default_desc));
                }
            }

            @Override
            public void onFail(String errorCode) {
                //默认页面
                default_view.setVisibility(View.GONE);
                default_view.setTextView(errorCode);
            }
        });

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){//返回
            finish();
        }else if (v.getId()==R.id.tv_withdraw){//提现按钮

            Util.setIntent(BalanceActivity.this, WithdrawActivity.class);
        }else if (v.getId()==R.id.img_right||v.getId()==R.id.tv_all) {//余额变动明细
            Util.setIntent(BalanceActivity.this, BalanceChangeDetailsActivity.class);
        }
    }

}
